<?php

namespace App\Admin\Controllers;

use App\Models\Apply;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ApplyController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '申请列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Apply());
        $grid->model()->orderByDesc('id');

        $grid->column('id', __('ID'));
        $grid->column('name', __('name'));
        $grid->column('phone', __('phone'));
        $grid->column('idcard', __('idcard'));
        $grid->column('worker', __('worker'));
        $grid->column('money', __('money'));
        $grid->column('created_at', __('created_at'));
        $grid->column('updated_at', __('updated_at'));


        $grid->filter(function (Grid\Filter $filter)  {

            $filter->expand();

            $filter->equal('name','name');
            $filter->equal('phone','phone');
            $filter->equal('idcard','idcard');
            $filter->between('created_at', 'created_at')->datetime();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Apply::findOrFail($id));

        $show->field('id', __('ID'));
        $show->field('name', __('名字'));
        $show->field('phone', __('电话'));
        $show->field('idcard', __('身份证号'));

        $show->field('worker', __('职业'));
        $show->field('money', __('金额'));

        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Apply());

        $form->display('id', __('ID'));
        $form->text('name', __('名字'));
        $form->text('phone', __('电话'));

        $form->text('idcard', __('身份证号'));
        $form->text('worker', __('职业'));
        $form->text('money', __('金额'));


        return $form;
    }
}
